<script type="text/javascript" src="<?php echo URL::base(); ?>media/js/jquery.min.js"></script>
<script src="<?php echo URL::base() ?>media/layer/layer.js"></script>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		
		<style media="print"> 
			.Noprint{display: none;}  
	
		</style>  
		 
		<style type="text/css">
			.printer {
							
							width: 172mm;
							font-family:Arial, Helvetica, sans-serif; 
 							font-size:15px; 
							margin-top:1px;
							margin-left:15px;
						}
				.zysx{
                  position: relative;
                  font-family:'宋体';
             }		
				.imgbox {
							position: absolute;
							 right: 150px;
               top: 400px;
					}
			tr{height:12mm;}

		</style> 
	
		<script type="text/javascript" language="javascript">

			function doPrint() {
				var ids = $("#idsqw").val();
 				window.print();

				//修改打印的采购单的状态
				var xmlhttp=getXmlHttpObject();
				//获取采购单的ID
				var ids=document.getElementById('ids').innerHTML;
				var url="insertdata";
				var str= $("#condition").val();//
				var strs= new Array();
				strs=str.split("::");//
				var urls= "?date_from="+strs[0]+"&date_to="+strs[1]+"&purchaseorder_id="+strs[2]+"&supplier_id="+strs[3]+"&supplier_name="+strs[4]+"&sku="+strs[5]+"&store="+strs[6]+"&status="+strs[7];
				xmlhttp.onreadystatechange=function ()
				{
					if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete"){
//                        alert(xmlhttp.responseText);
						layer.confirm(xmlhttp.responseText+'是否返回待打印界面？', {
                            btn: ['确定','取消'] //按钮
                        }, function(){
                            window.location.href="<?php echo url::base(true);?>purchases/select/purchaseindex"+urls;
                        }, function(){

                        });
							
					}	
				};

				xmlhttp.open("POST",url,true);
				xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
				xmlhttp.send("ids="+ids);
				
			}

			//获取ajax对象
			function getXmlHttpObject(){
				var xmlHttp=null;
				try{
				 // Firefox, Opera 8.0+, Safari
					xmlHttp=new XMLHttpRequest();
				}catch (e)
				{
				 	// Internet Explorer
					try{
						
					  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
					  
					}catch (e)
					{
					  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
					}
				}
					return xmlHttp;
			}
				
	</script>
		
	</head>
	
	<body style=" margin:0;">
	<div >
		<span style="display:none;" id="ids"><?php echo $ids?></span>
		<div class="printer">
			<div > 
			<?php if(!empty($purchaseprints)){?>
				<?php foreach ($purchaseprints as $purchaseprint)
							{
								
				?>
			 		<div align="center"><strong style="font-size:24px">有棵树集团预约单</strong></div>
			    <div align="center">交货地址:
                    <?php if($purchaseprint['store']==5){?>苏州市吴中经济开发区郭巷街道官浦路1号（玄通集团现代电商产业园内2楼）有棵树集团
                     <?php }else{?>深圳市龙岗区平湖镇平安大道华南城海关保税仓6楼（前门） <?php }?>
                                </div>
                <?php $user_id   = User::active_user()->id;
                $userSql   = "SELECT `mail` from  users WHERE `id` = $user_id";
                $user_mail = DB::query(Database::SELECT,$userSql)->execute('default')->as_array();
                $_mail     = explode('@',$user_mail[0]['mail']);
                $mail      = $_mail[0];

                ?>
                <div align="center">
                    <strong>
                        采购员：<?php echo  ORM::factory('user',$purchaseprint['purchase_id'])->nick; ?>
                        &nbsp;&nbsp;&nbsp;
                        联系电话：<?php echo $mail ?>
                    </strong>
                </div>

                 <div align="center">国内仓供应链计划管理部经理：刘萍  电话：15986849605</div>

                <div align="center">（若联系不上采购，请联系经理！）</div>


				
				 <div align="center" >  
					<table cellpadding="0" cellspacing="0"  width="100%"  border="1px">
					   
					   <tr height="12">
						    <td colspan="14" align="center" >
									<div style="float:left;text-align:left; padding-left:20px; width:50%; padding-top:10px; padding-bottom:10px;"  >供 应 商:<?php echo $purchaseprint['vProviderName'] ?>(<?php echo $purchaseprint['supplier_id']?>)
									<br>订购日期: <?php echo $purchaseprint['purchaseorder_date']?><br>付款方式：<?php 
									//------------------------------kdw-----------------------
//									$sta=DB::select()->from('erp_pay_type')
//									->where('id','=',$purchaseprint['pay_way'])
//									->execute('readonlyerp')->current();

                                    $sta=DB::query(Database::SELECT,'SELECT id,paywayname AS type FROM payways WHERE id='.$purchaseprint['pay_way'])
                                            ->execute('newerp')->current();
                                    echo $sta['type'];
                                    //------------------------------kdw-----------------------
									?>
									 &nbsp;&nbsp;<br>TEL:<?php echo $purchaseprint['vPhone']?>手机：<?php echo $purchaseprint['vMobile']?>
                                        <br>运费:<?php echo $purchaseprint['transportation_expense']?>
                                    </div>
									<div  style="float:riht;text-align:left ;padding-left:20px; padding-top:10px;padding-bottom:10px;"  >预约单号：<?php echo $purchaseprint['id']?><br>联 络 人：<?php echo $purchaseprint['vContact'] ?><br>
                                        <!--yuqing '人民币=》'$purchaseprint['coin']-->
									币种：<?php echo $purchaseprint['coin']; ?>, 仓库：<label style="font-size: large; font-weight: bold"><?php echo $purchaseprint['storeName'];?></label>
									<br>FAX:<?php echo $purchaseprint['vFax'] ?>　</div>
								</td>
					    </tr>
					    
						  <tr height="12mm">
						    <td width="48" align="center">项次</td>
						    <td align="center" width="100">SKU</td>
						    <td align="center" width="90" >报关品名</td>
						    <td align="center" width="60" >数量</td>
						    <td align="center" width="50">单位</td>
						    <td align="center" width="50">采购名称</td>
						    <td width="50" align="center" >图片</td>
                              <td  align="center" > 品牌</td>
                              <td  align="center" > 型号</td>
							  <td width="50" align="center" > 单价</td>
								<!--
								取消显示税率信息，增加显示规格信息
								@time 20140814
								<td width="50" align="center" > 计税方式</td>
								<td width="50" align="center" > 税率</td>
								<td width="50" align="center" > 税额</td>
								<td width="50" align="center" > 未税金额</td>-->
							  <td width="50" align="center" > 金额</td>
						    <td align="center" width="104" >交货日期</td>
						    <td width="70" align="center">状态</td>
						  </tr>
						  
					  	<?php 
											$sql = "SELECT `id`,`sku`,`sku_name`,`quantity`,`single_price`,`remark`,`arrive_date`,`tax_rate`,`item`,`tax_way`,`tax_money`,`money`,`no_tax_money` ,`sku_standard`
															FROM  `purchaseorder_details` 
															WHERE `status` <= 90 AND `purchaseorder_id` = ".$purchaseprint['id'];
											$pod = DB::query(Database::SELECT,$sql)->execute('newerp')->as_array();
											foreach($pod as $key=>$value)
											{	
												unset($image);
                                                $postData = array(
                                                    "sku"        => trim($value['sku']),
                                                    "gallery_id" => '1',
                                                    "type"       => "ALL",
                                                    "all_type"   => "false",
                                                    "url_type"   => 'http'
                                                );
                                                $image = Skusystemapi::getSkuSystemImgData($postData);//获取图片

//												$image = service_skudetail::get_erp_images($value['sku']);//获取图片
//                                              -------------------------------------kdw--------------------------------
//												$sql = "SELECT `nuit`
//																FROM `erp_providerproducts`
//																WHERE `iproductID`='".$value['sku']."' and `iproviderID`=".$purchaseprint['supplier_id'];
//												$s_info = DB::query(Database::SELECT,$sql)->execute('readonlyerp')->current();

                                                $s_info=Newerpclientapi::getSupplierSkuBy($purchaseprint['supplier_id'],$value['sku']);
//                                              -------------------------------------kdw-end----------------------------
												$pod[$key]['products_id'] = $products['products_id'];
												$pod[$key]['products_imagess'] = $image;

												$pod[$key]['nuit']             = $s_info['nuit'];
												if($value['tax_way']==1)
													$pod[$key]['tax_way']='外加税';
												else if($value['tax_way']==-1)
													$pod[$key]['tax_way']='内含税';
												else
													$pod[$key]['tax_way']='不计税';				
											}
								/* $purchasedetails=new Service_Purchasedetaillist();
								 if(isset($purchaseprint['id'])){
									 $purchasedetailslist=$purchasedetails->set('ipurchaseID', $purchaseprint['id'])->Get_list()->find_all();
						 			 foreach ($purchasedetailslist as $index=> $purchasetail)
									  {
											$product=DB::select('products_imagess','products_id')
																		->from('erp_products_data')
																		->execute('erpdatabase');
							*/?>
						<?php foreach($pod as $k=>$p){ 
							$skuinfo = Basic::get_sku_status(array($p['sku']));
							$skuinfo_single = $skuinfo[strtoupper($p['sku'])];?>
							  <tr height="12mm" >
							    <td align="center"><?php echo $k+1; ?></td>
							    <td align="center" width="100"><?php echo $p['sku'] ?></td>
							    <td align="center" width="180"><?php echo $p['item']?></td>
							    <td width="50" align="center"><?php echo $p['quantity'] ?></td>
									<td width="50" align="center"><?php echo $p['nuit'] ?></td>　
                                  <td align="center" ><?php echo $p['sku_name'] ?></td>
									<td >
									 	<img src="<?php echo $p['products_imagess'] ?>" style="width:100;height:100;" />
									</td>
							    <td align="center" width="50"></td>
							    <td align="center" width="50"></td>
							    <td align="center" width="50"><?php echo sprintf("%.3f",$p['single_price']) ?></td>
									<!--
									取消显示税率信息，增加显示规格信息
								    @time 20140814
									<td align="center" width="50"><?php /*echo $p['tax_way'] */?></td>
									<td align="center" width="50"><?php /*echo strval(sprintf("%.2f",$p['tax_rate'])*100)."%" */?></td>
									<td align="center" width="50"><?php /*echo sprintf("%.2f",$p['tax_money']) */?></td>
									<td align="center" width="50"><?php /*echo sprintf("%.2f",$p['no_tax_money']) */?></td>
									-->
							    <td align="center" width="50"><?php echo sprintf("%.2f",$p['money']) ?></td>
							    <td align="center" width="103"><?php echo date('Y-m-d',strtotime($p['arrive_date'])); ?></td>
							  	<td align="center" width="70"><?php if(isset($skuinfo_single['status_string'])){ echo $skuinfo_single['status_string'];}else{ echo "未知状态";} ?></td>
							  </tr>
							  <?php }?>
						  <tr >
						     <td align="left" colspan="14"><div style="float:left;text-align:left; padding-left:20px;padding-top:10px; width:50%;"  >备注: <?php echo $purchaseprint['remark'] ?></div><div  style="float:riht;text-align:left ;padding-left:20px; padding-top:10px;" >  总计:  <?php echo sprintf("%.2f",$purchaseprint['money']+$purchaseprint['transportation_expense']); //Purchase::select_total_purchase($purchaseprint['id']);?>  </div></td>
						  </tr>
					  </table>
					 </div>
					 
					 <div class="zysx" >
						  <br>
                         1、本预约单是作为前期与贵供应商约定的形式，不作为正式采购订单；<br>

                         2、待该产品产生销售订单后，该预约单会转化与分解成正式采购订单给到贵供应商，具体订单信息以我司后续的正式订购单为准。<br>

                         3、届时我司会按照发票提供时效第一时间进行退税模块请款，其他按照非出口退税模块正常请款；<br>

                         4、请贵供应商注意贴注箱唛信息：采购跟单、sku、订单号、pcs<br>



						 
						 <div  style="text-align:right ;padding-left:20px; padding-top:10px;margin-bottom: 10px;" >
						 		日期:&nbsp;&nbsp;&nbsp;&nbsp;年&nbsp;&nbsp;&nbsp;月&nbsp;&nbsp;&nbsp;日&nbsp;&nbsp;&nbsp;&nbsp;
						 </div>

					 </div>
					<div style="page-break-after:always;"></div>
					
									
				<?php }?>
				<div style=" overflow:hidden;">
					<div style="float: left;margin-left: 200px;" align="center" class="Noprint">
						<input style="padding: 10px 20px;font-size: 24px;background-image: linear-gradient(to bottom, #62c462, #51a351);border: 1px solid #fff;color: #fff;font-weight: bold;word-spacing: 7px;border-radius: 10px;outline: none;" type="button" value="打印"    onclick="doPrint();">
					</div>
					<div style="float: left;margin-left: 20px;border-radius: 10px;" align="center" class="Noprint">
					<!-- 
						<input type="button" value="确定"    onclick="doPrint();"> -->
						<input style="padding: 10px 20px;font-size: 24px;border-radius: 10px;color: #fff;outline: none;background-color: #666;font-weight: bold;border: 1px solid #fff;" type="button" value="返回"    onclick="location.href='<?php echo url::base(true);?>/purchases/select/purchaseindex'" />
					</div>
				</div>
			<?php }?>
			</div>
			<div style="display:none"><input type="text" value="<?php if(isset($condition)) echo $condition; ?>" id="condition"></div>
			<input type="text" name="ids" id="idsqw" value="<?php if(isset($ids)) echo $ids?>" style="display:none"/>
			<?php if(isset($effect)){?>
			<div>
			<h><?php echo $effect?></h>
			<input type="button" value="返回"    onclick="location.href='<?php echo url::base(true);?>/purchases/select/searchpurchase'" />
			</div>
			<?php }?>
			
		</div>
	</div>		
	</body>
</html>
